"""
@author: 方杰
@file: 验证ipv4地址合法性.py
@time: 2023/6/4 14:11
"""
# 验证ipv4的合法性
# 1~125.1~125.1~125.1~125
import re

ipv4 = input("请输入一个ipv4的地址:")
result = re.findall\
    (r"^([1-9]\.|[1-9]\d\.|1\d{2}\.|2[0-4]\d\.|25[0-5]\.){3}([1-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])", ipv4)
if result:
    print(f"该{ipv4}合法")
else:
    print(f"该{ipv4}不合法")